<template>
	<view class="wrap">
		<block v-if="dataBuffer">
			<view class="top">
				<image :src="headImg" mode="widthFix" class="topBanner"></image>
				<image src="../../static/active.png" mode="widthFix" class="bottomBanner"></image>
			</view>
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.img" :index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.goodsname}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							小U自营
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.img" :index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.goodsname}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							小U自营
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon>
					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</block>
		<!-- 无数据提示 -->
		<u-empty 
			text="暂无数据~~去逛逛~~" mode="list" 
			:show="!dataBuffer" 
			color="orange" icon-color="orange"
		></u-empty>
	</view>
</template>

<script>
	// 引入测试数据 可以测试使用
	import list from '@/utils/active.data.js'
	export default {
		data() {
			return {
				headImg:'',
				activeData:{},
				loadStatus: 'loadmore',
				flowList: [],
				page:1,
				size:4,
				totalPage:0,
				dataBuffer:true
			}
		},
		onLoad(option){
			this.activeData = JSON.parse(option.params);
			//设置头部图片
			this.headImg = JSON.parse(option.params).img;
			
			
			
			this.getlist()
		},
		onReachBottom() {
			if(this.page<this.totalPage){
				this.loadStatus="loading"
				setTimeout(()=>{
					++this.page
					this.getlist()
				},1500)
			}else{
				this.loadStatus="nomore"
			}
		},
	
		methods: {
			getlist(){
					//设置标题
					uni.setNavigationBarTitle({
						title:this.activeData.title
					})
					//获取列表数据
					this.$http({url:"getgoodlist",data:{cateid:this.activeData.second_cateid,page:this.page,size:this.size,type:2}}).then(res=>{
						let {goodData,totalPage} = res.list
						//如果没有数据 
						if(totalPage==0){
							this.dataBuffer = false
						}else{
							//检测是否有更多数据
							if(totalPage==1){
								this.loadStatus='nomore'
							}else{
								this.loadStatus="loading"
							}
							goodData.forEach(item=>{
								item.img = this.$url+item.img
							})
							//拼接下一页数据：原数据+新数据
							this.flowList = this.flowList.concat(goodData);
							
							this.totalPage = totalPage
						}
					})
			},
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			}
		}
	}
</script>

<style lang="scss" scoped>
	// 引入样式
	@import '@/static/css/active.scss'
</style>
